﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;

using DQYT.HTDZ.BLL;
using DQYT.HTDZ.Model;

namespace DQYT.HTDZ.Web.BDDATESOURSE
{
    public partial class Modify : Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                {
                    decimal ID = (Convert.ToDecimal(Request.Params["id"]));
                    ShowInfo(ID);
                }
            }
        }

        private void ShowInfo(decimal ID)
        {
            BDDATESOURSEBLL bll = new BDDATESOURSEBLL();
            BDDATESOURCEModel model = bll.GetModel(ID);
            this.lblID.Text = model.ID.ToString();
            this.txtWELLID.Text = model.WELLID;
            this.txtJCRQ.Text = model.JCRQ.ToString();
            this.txtKSSJ.Text = model.KSSJ.ToString();
            this.txtJSSJ.Text = model.JSSJ.ToString();
            this.txtCJZSJ.Text = model.CJZSJ.ToString();
            this.txtCJPL.Text = model.CJPL.ToString();
            this.txtCJZDS.Text = model.CJZDS.ToString();
            this.txtSCCDS.Text = model.SCCDS.ToString();
            this.txtXCCDS.Text = model.XCCDS.ToString();
            this.txtPULLID.Text = model.PULLID.ToString();
            this.txtDJID.Text = model.DJID.ToString();
            this.txtPDGID.Text = model.PDGID.ToString();
            this.txtGLDW.Text = model.GLDW;
            this.txtJCDW.Text = model.JCDW;
            this.txtCSR.Text = model.CSR;
            this.txtCJSBXH.Text = model.CJSBXH;
            this.txtCJSBBB.Text = model.CJSBBB;
            this.txtSCRJBB.Text = model.SCRJBB;
            this.txtCJSJ.Text = model.CJSJ.ToString();

        }

        public void btnSave_Click(object sender, EventArgs e)
        {

            string strErr = "";
            if (this.txtWELLID.Text.Trim().Length == 0)
            {
                strErr += "WELLID不能为空！\\n";
            }
            if (!PageValidate.IsDateTime(txtJCRQ.Text))
            {
                strErr += "JCRQ格式错误！\\n";
            }
            if (!PageValidate.IsDateTime(txtKSSJ.Text))
            {
                strErr += "KSSJ格式错误！\\n";
            }
            if (!PageValidate.IsDateTime(txtJSSJ.Text))
            {
                strErr += "JSSJ格式错误！\\n";
            }
         //   if (!PageValidate.IsTimeSpan(txtJSSJ.Text))
           // {
            //    strErr += "JSSJ格式错误！\\n";
           // }
             
            if (!PageValidate.IsDecimal(txtCJPL.Text))
            {
                strErr += "CJPL格式错误！\\n";
            }
            if (!PageValidate.IsDecimal(txtCJZDS.Text))
            {
                strErr += "CJZDS格式错误！\\n";
            }
            if (!PageValidate.IsDecimal(txtSCCDS.Text))
            {
                strErr += "SCCDS格式错误！\\n";
            }
            if (!PageValidate.IsDecimal(txtXCCDS.Text))
            {
                strErr += "XCCDS格式错误！\\n";
            }
            if (!PageValidate.IsDecimal(txtPULLID.Text))
            {
                strErr += "PULLID格式错误！\\n";
            }
            if (!PageValidate.IsDecimal(txtDJID.Text))
            {
                strErr += "DJID格式错误！\\n";
            }
            if (!PageValidate.IsDecimal(txtPDGID.Text))
            {
                strErr += "PDGID格式错误！\\n";
            }
            if (this.txtGLDW.Text.Trim().Length == 0)
            {
                strErr += "GLDW不能为空！\\n";
            }
            if (this.txtJCDW.Text.Trim().Length == 0)
            {
                strErr += "JCDW不能为空！\\n";
            }
            if (this.txtCSR.Text.Trim().Length == 0)
            {
                strErr += "CSR不能为空！\\n";
            }
            if (this.txtCJSBXH.Text.Trim().Length == 0)
            {
                strErr += "CJSBXH不能为空！\\n";
            }
            if (this.txtCJSBBB.Text.Trim().Length == 0)
            {
                strErr += "CJSBBB不能为空！\\n";
            }
             if (this.txtSCRJBB.Text.Trim().Length == 0)
            {
                strErr += "SCRJBB不能为空！\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            decimal ID = decimal.Parse(this.lblID.Text);
            string WELLID = this.txtWELLID.Text;
            DateTime JCRQ = DateTime.Parse(this.txtJCRQ.Text);
            DateTime KSSJ = DateTime.Parse(this.txtKSSJ.Text);
            DateTime JSSJ = DateTime.Parse(this.txtJSSJ.Text);
            string CJZSJ = this.txtCJZSJ.Text;
            decimal CJPL = decimal.Parse(this.txtCJPL.Text);
            decimal CJZDS = decimal.Parse(this.txtCJZDS.Text);
            decimal SCCDS = decimal.Parse(this.txtSCCDS.Text);
            decimal XCCDS = decimal.Parse(this.txtXCCDS.Text);
            decimal PULLID = decimal.Parse(this.txtPULLID.Text);
            decimal DJID = decimal.Parse(this.txtDJID.Text);
            decimal PDGID = decimal.Parse(this.txtPDGID.Text);
            string GLDW = this.txtGLDW.Text;
            string JCDW = this.txtJCDW.Text;
            string CSR = this.txtCSR.Text;
            string CJSBXH = this.txtCJSBXH.Text;
            string CJSBBB = this.txtCJSBBB.Text;
            string SCRJBB = this.txtSCRJBB.Text;
            byte[] CJSJ = new UnicodeEncoding().GetBytes(this.txtCJSJ.Text);


            BDDATESOURCEModel model = new BDDATESOURCEModel();
            model.ID = ID;
            model.WELLID = WELLID;
            model.JCRQ = JCRQ;
            model.KSSJ = KSSJ;
            model.JSSJ = JSSJ;
            model.CJZSJ = CJZSJ;
            model.CJPL = CJPL;
            model.CJZDS = CJZDS;
            model.SCCDS = SCCDS;
            model.XCCDS = XCCDS;
            model.PULLID = PULLID;
            model.DJID = DJID;
            model.PDGID = PDGID;
            model.GLDW = GLDW;
            model.JCDW = JCDW;
            model.CSR = CSR;
            model.CJSBXH = CJSBXH;
            model.CJSBBB = CJSBBB;
            model.SCRJBB = SCRJBB;
            model.CJSJ = CJSJ;

            BDDATESOURSEBLL bll = new BDDATESOURSEBLL();
            bll.Update(model);
            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "list.aspx");

        }


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
